<template>
    <el-form :inline="true" :model="Page" class="demo-form-inline">
        <el-form-item label="派工编号">
      <el-input v-model="Page.DNumber"  clearable />
    </el-form-item>
    <el-form-item label="派工主题">
      <el-input v-model="Page.DisTopic"  clearable />
    </el-form-item>
    <el-form-item label="添加人">
      <el-input v-model="Page.AddName"  clearable />
    </el-form-item>
    <el-form-item label="产品名称">
      <el-input v-model="Page.PName"  clearable />
    </el-form-item>
    <el-form-item label="派工日期">
        <el-date-picker
        v-model="Page.SDDeliveryDate"
        type="datetime"
        placeholder="Pick a Date"
        format="YYYY/MM/DD hh:mm:ss"
        value-format="YYYY-MM-DD h:m:s a"
      />-
      <el-date-picker
        v-model="Page.EDDeliveryDate"
        type="datetime"
        placeholder="Pick a Date"
        format="YYYY/MM/DD hh:mm:ss"
        value-format="YYYY-MM-DD h:m:s a"
      />
    </el-form-item>
    <el-form-item label="被派人员">
      <el-input v-model="Page.ManpowerName"  clearable />
    </el-form-item>
    <el-form-item label="派工状态">
      <!-- <el-input v-model="Page.DState"  clearable /> -->
      <el-select v-model="Page.DState" placeholder="全部" style="width: 200px;" clearable>
        <el-option label="未开始" :value="1" />
        <el-option label="生产中" :value="2" />
        <el-option label="生产完毕" :value="3" />
        <el-option label="超期生产中" :value="4" />
        <el-option label="滞期未开始" :value="5" />
      </el-select>
    </el-form-item>
    <el-form-item label="领料状态">
      <!-- <el-input v-model="Page.DPickState"  clearable /> -->
      <el-select v-model="Page.DPickState" placeholder="全部" style="width: 200px;">
        <el-option label="无需领料" :value="1" />
        <el-option label="未领料" :value="2" />
        <el-option label="部分领料" :value="3" />
        <el-option label="领料完毕" :value="4" />
      </el-select>
    </el-form-item>
    </el-form>
          <el-button type="primary" @click="router.push({ name: 'DisPatchAdd'})">新增</el-button>
          <el-button type="primary" @click="Del">删除</el-button>
          <el-button type="primary" @click="Show">查询</el-button>
          <el-button type="primary" @click="UpdProduct">修改</el-button>
  <el-table :data="GetShow" style="width: 100%"  @selection-change="handleSelectionChange">
    <el-table-column type="selection" width="55" />
    <el-table-column prop="dNumber" label="生产派工编号" width="200" />
    <el-table-column prop="disTopic" label="生产派工主题" width="180" />
    <el-table-column prop="pName" label="派工产品" width="180" />
    <el-table-column prop="dThisNum" label="本次派工数量" width="180" />
    <el-table-column prop="dpStartDate" label="计划开工日期" width="180" >
        <template #default="scope">
        <sapan >{{ (scope.row.dispatchProducts[0].dpStartDate).substring(0,10)}}</sapan>
      </template>
    </el-table-column>
    <el-table-column prop="dpEndDate" label="计划完工日期" width="180" >
        <template #default="scope">
        <sapan >{{ (scope.row.dispatchProducts[0].dpEndDate).substring(0,10)}}</sapan>
      </template>
    </el-table-column>
    <el-table-column prop="dispatchProducts" label="交货日期" width="180">
        <template #default="scope">
        <sapan >{{ (scope.row.dispatchProducts[0].dDeliveryDate).substring(0,10)}}</sapan>
      </template>
    </el-table-column>
    <el-table-column prop="manpowerName" label="被派人员" width="180" />
    <el-table-column prop="dState" label="派工状态" width="180" />
    <el-table-column prop="dPickState" label="领料状态" width="180" />
    <el-table-column prop="addName" label="制单人员" width="180" />
    <el-table-column prop="addTime" label="制单日期" width="180" />
    <el-table-column prop="address" label="操作">
      <template #default="scope">
        <button @click="zhi(scope.row.dispatchId)">质检</button>
      </template>
    </el-table-column>
  </el-table>

</template>
<script setup lang="ts">
import axios from 'axios'
import { ElMessage, ElMessageBox } from 'element-plus';
import { ref, reactive, onMounted, computed } from 'vue'
import { useRouter, useRoute } from 'vue-router';
const router = useRouter();
const route = useRoute();
import http from '../../../http.js' 
onMounted(() => {
    Show()
})
const Page=reactive ({
pageIndex:1,
pageSize:10,
totalCount:0,
pageCount:0,
DisTopic:'',
ManpowerName:'',
PName:'',
SDDeliveryDate:'',
EDDeliveryDate:'',
DNumber:'',
DState:'',
DPickState:'',
AddName:''


})


const GetShow=ref([])
const Show=()=>{
    axios.get(http.zblnb+'/sc/api/DisPatch/ShowDisPatch',{
        params:{
            PageIndex:Page.pageIndex,   
            PageSize:Page.pageSize, 
            DisTopic:Page.DisTopic,
            ManpowerName:Page.ManpowerName,
            PName:Page.PName,
            AddName:Page.AddName,
            SDDeliveryDate:Page.SDDeliveryDate,
            EDDeliveryDate:Page.EDDeliveryDate,
            DNumber:Page.DNumber,
            DState:Page.DState||'',
            DPickState:Page.DPickState||''
        }
    }).then((res) => {
        console.log(res.data.data.list)
        GetShow.value=res.data.data.list
        Page.totalCount=res.data.data.totalCount
        Page.pageCount=res.data.data.pageCount
    })
}
const check = ref([])
const handleSelectionChange = (val: any) => {
    check.value = val
}
const Del = () => {
    if (check.value.length == 0) {
        return ElMessage("请选择要删除的记录")
    }
    ElMessageBox.confirm(
        '此操作将永久删除该记录, 是否继续?',
        '提示',
        {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
        }
    ).then(() => {
       
        let id = check.value.map((item: any) => item.dispatchId)
        var model = {
            dispatchId: id,
            delName:''
        }
        console.log(id)
        axios.post(http.zblnb+'/sc/api/DisPatch/DelDisPatch', model).then(res => {
            if (res.data.data > 0) {
                ElMessage.success("删除成功")
                Show()
            } else {
                ElMessage.error("删除失败")
            }
        })
    })
}
//修改
const UpdProducts=ref({})
const UpdProduct = () => {
    if (check.value.length == 0) {
        ElMessage.error('请选择要修改的数据');
        return
    }
    if (check.value.length >1) {
        ElMessage.error('要修改的数据只能选择一条');
        return
    }
    UpdProducts.value = check.value[0]
    console.log(UpdProducts.value)
   router.push("DisPatchUpd?id="+UpdProducts.value.dispatchId)
}













const zhi=(id:number)=>{
  router.push("SFQICreate?id="+id)

}

</script>